clear all

/*

The code is for the paper "Attribution of Blame for Food Waste" by Eliot Martin, Eliza Hallette, Linlin Fan, Brenna Ellison, and Norbert Wilson.
The data set is from a larger data set of a choice expeirment on food waste led by Brenna Ellison.

*/
use "C:\Users\nlw30\Box\Food Waste\Choice Experiment\Food Waste CE\Eliot and Eliza\ATTRIBUTION OF FOOD WASTE BLAME.dta"

**Data transformations**




recode race (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0), gen(white)
/*
white is a binary variable that represents if a respondent reports that they are white.

What is your race/ethnicity?
White/Caucasian (1) 
Black/African American (2) 
Hispanic or Latino/a (3) 
American Indian or Alaska Native (4) 
Asian/Pacific Islander (5) 
More than one race (7) 
Other (please specify): (6) ________________________________________________


*/
recode numkids (0=0) (1=1) (2=1) (3=1) (4=1), gen(children)

/*
children is a binary variable that represeent the presend of chilldren under 18y.

How many children under 18 years of age are currently living in your household?
0 children (0) 
1 child (1) 
2 children (2) 
3 children (3) 
4 or more children (4) 

*/


gen foodassist=.
replace foodassist=1 if snap==1 | pantry==1
replace foodassist=0 if snap==0 & pantry==0

/*

foodasst is a binary variable that represents reciept of SNAP, WIC, or food from the charitable food sector.

In the past 12 months, have you received SNAP or WIC benefits?
Yes (1) 
No (0) 

In the past 12 months, did you receive food from a food pantry (shelf), soup kitchen, or other charity?
Yes (1) 
No (0) 


*/

recode edu (1=0) (2=0) (3=0) (4=0) (5=1) (6=1), gen(collegedegree)

/*

collegedegree is a binary varaible if the repsonsdent has a Bachelor's Degree or Advancd Degree

What is your current highest level of education?
Some High School (1) 
High School Diploma / GED (2) 
Associates or Technical Degree (3) 
Some College (4) 
Bachelor's Degree (5) 
Advanced Degree (MS, MA, PhD, MD, JD, etc) (6) 

*/


recode uneaten (1=0) (2=1) (3=1) (4=1) (5=0), gen(altusefoodwaste)
/*

altusefood is a binaary variable the indicates use of food that is uneaten
uneaten is the response to the response to the following question:

 What does your household typically do with food that is not eaten?
Throw uneaten food in the garbage (1) 
Give uneaten food to a pet (2) 
Compost uneaten food (3) 
Donate uneaten food (4) 
Other (5) ________________________________________________
*/



**** Food Waste Mitigating Strategies ****
/*
The key independent variable is the type and number of Food Waste Mitigating Strategies.
The responses are from the following question:

Do you engage in the following activities related to grocery shopping? Yes (1)	No (2)
I typically use a list when grocery shopping.
I typically use coupons or look up sales in grocery circulars.
I typically buy items in bulk at the grocery store to save money.
I typically shop at more than one store for my groceries.
I typically purchase my groceries online.   
I typically get my groceries through meal services such as Blue Apron, Hello Fresh, or Plated. 

The received data set was recoded as
0 No
1 Yes

*/

g unbulk = bulk
recode unbulk (0=1) (1=0)
***unbulk is a binary variable that signifies if a shopper shops at a bulk mechandiser***


g foodsaversall= list+online+mealkit+coupons+altusefoodwaste+unbulk+multistore
replace foodsaversall=6 if foodsaversall>=6 

g foodsaver1=list
g foodsaver2=online
g foodsaver3=mealkit
g foodsaver4=coupons
g foodsaver5=altusefoodwaste
g foodsaver6=multistore
g foodsaver7=unbulk




****** OUTCOME VARIABLE ***********


recode blamegovt blamefs blamegroc blamefm blamefarm blameind (0=3) (1=2) (2=1), gen(bgov bfoods bgroc bfman bfarm bind)
/*
The outcome variable is blame* for each stakeholder. We recoded the resposne so that Not to Blame is 1, Somewhat to Blame is 2,
and Primarily to Blame is 3.

Who is primarily to blame for the amount of food that is wasted in the United States?  Click and drag each item to the appropriate box. 
If no one is to blame, drag all items to the "Not to Blame" box.

Primarily to Blame			Somewhat to Blame			Not to Blame

Government policies 
Restaurants & Food Service 
Grocery stores
Food manufacturers 
Farmers 
Individuals 


*/

label define blame 1 "Not to Blame" 2 "Somewhat to Blame" 3 "Primarily to Blame"

label values bind blame
label values bgov blame
label values bfoods blame
label values bgroc blame
label values bfman blame
label values bfarm blame


*Mean, Standard Deviaion, and Coefficeint of Variation of the blame score accross stakeholders by respondent
egen float XBARI=rowmean(bgov bfoods bgroc bfman bfarm bind)
egen float XSDI = rowsd(bgov bfoods bgroc bfman bfarm bind)
egen float VBARI = rowsd(bgov bfoods bgroc bfman bfarm bind)
g XCVI=XSDI/XBARI


g blame1=bfarm
g blame2=bgov
g blame3=bgroc
g blame4=bfman
g blame5=bind
g blame6=bfoods

********** STATISTICAL ANALYSIS **************


**** Estamate of Mean (XBARI) and the CV (XCVI) of the Blame Score *****

** Unadjusted **
eststo: reg XBARI i.list i.online i.mealkit i.coupons i.altusefoodwaste i.multistore i.unbulk
eststo: reg XBARI c.foodsaversall

** Adjusted ***
eststo: reg XBARI c.foodsaversall i.region i.collegedegree i.sex i.income i.foodassist i.white i.age c.hhsize i.children
eststo: reg XBARI i.list i.online i.mealkit i.coupons i.altusefoodwaste i.multistore i.unbulk i.region i.collegedegree ///
		i.sex i.income i.foodassist i.white i.age c.hhsize i.children

		
** Unadjusted **		
eststo: reg XCVI i.list i.online i.mealkit i.coupons i.altusefoodwaste i.multistore i.unbulk
eststo: reg XCVI c.foodsaversall

** Adjusted **
eststo: reg XCVI c.foodsaversall i.region i.collegedegree i.sex i.income i.foodassist i.white i.age c.hhsize i.children
eststo: reg XCVI i.list i.online i.mealkit i.coupons i.altusefoodwaste i.multistore i.unbulk i.region i.collegedegree ///
		i.sex i.income i.foodassist i.white i.age c.hhsize i.children


esttab using finalreshaped1_2b.csv, unstack b(3) se(3) star(+ 0.05 * 0.01) replace
	eststo clear


**** Key Regressions of Blame Scores *****

** Unadjusted SUR of Blame Scores on Ennumerated Food Waste Mitigating Activities **
eststo: sureg (Farmers:  bfarm = i.list i.mealkit i.online i.coupons i.altusefoodwaste i.multistore i.unbulk ) ///
		(Food_Manufacturers: bfman = i.list i.mealkit i.online i.coupons i.altusefoodwaste i.multistore i.unbulk ) ///
		(Government:  bgov = i.list i.mealkit i.online i.coupons i.altusefoodwaste i.multistore i.unbulk) ///
		(Grocery_Stores: bgroc = i.list i.mealkit i.online i.coupons i.altusefoodwaste i.multistore i.unbulk) ///
		(Individuals: bind =  i.list i.mealkit i.online i.coupons i.altusefoodwaste i.multistore i.unbulk) ///
		(Restaurant_FoodService:  bfoods = i.list i.mealkit i.online i.coupons i.altusefoodwaste i.multistore i.unbulk) 

sureg, notable noheader corr

** Adjusted SUR of Blame Scores on Ennumerated Food Waste Mitigating Activities**

eststo: sureg (Farmers:  bfarm = i.list i.mealkit i.online i.coupons i.altusefoodwaste i.multistore i.unbulk i.region i.collegedegree i.sex i.income ///
		i.foodassist i.white i.age c.hhsize i.children) (Food_Manufacturers: bfman = i.list i.mealkit i.online i.coupons i.altusefoodwaste i.multistore ///
		i.unbulk i.region i.collegedegree i.sex i.income i.foodassist i.white i.age c.hhsize i.children) (Government:  bgov = i.list i.mealkit i.online ///
		i.coupons i.altusefoodwaste i.multistore i.unbulk i.region i.collegedegree i.sex i.income i.foodassist i.white i.age c.hhsize i.children) ///
		(Grocery_Stores: bgroc = i.list i.mealkit i.online i.coupons i.altusefoodwaste i.multistore i.unbulk i.region i.collegedegree i.sex i.income ///
		i.foodassist i.white i.age c.hhsize i.children) (Individuals: bind =  i.list i.mealkit i.online i.coupons i.altusefoodwaste i.multistore i.unbulk ///
		i.region i.collegedegree i.sex i.income i.foodassist i.white i.age c.hhsize i.children) (Restaurant_FoodService:  bfoods = i.list i.mealkit ///
		i.online i.coupons i.altusefoodwaste i.multistore i.unbulk i.region i.collegedegree i.sex i.income i.foodassist i.white i.age c.hhsize i.children) 

sureg, notable noheader corr


** Unadjusted SUR of Blame Scores on the Number of Food Waste Mitigating Activities**

eststo: sureg (Farmers:  bfarm = c.foodsaversall) ///
		(Food_Manufacturers: bfman = c.foodsaversall) ///
		(Government:  bgov = c.foodsaversall) ///
		(Grocery_Stores: bgroc = c.foodsaversall) ///
		(Individuals: bind = c.foodsaversall) ///
		(Restaurant_FoodService:  bfoods = c.foodsaversall) 

sureg, notable noheader corr


** Adjusted SUR of Blame Scores on the Number of Food Waste Mitigating Activities**

eststo: sureg (Farmers:  bfarm = c.foodsaversall i.region i.collegedegree i.sex i.income i.foodassist i.white i.age c.hhsize i.children) ///
		(Food_Manufacturers: bfman = c.foodsaversall i.region i.collegedegree i.sex i.income i.foodassist i.white i.age c.hhsize i.children) ///
		(Government:  bgov = c.foodsaversall i.region i.collegedegree i.sex i.income i.foodassist i.white i.age c.hhsize i.children) ///
		(Grocery_Stores: bgroc = c.foodsaversall i.region i.collegedegree i.sex i.income i.foodassist i.white i.age c.hhsize i.children) ///
		(Individuals: bind = c.foodsaversall  i.region i.collegedegree i.sex i.income i.foodassist i.white i.age c.hhsize i.children) ///
		(Restaurant_FoodService:  bfoods = c.foodsaversall i.region i.collegedegree i.sex i.income i.foodassist i.white i.age c.hhsize i.children) 

sureg, notable noheader corr


esttab using finalreshaped1_a.csv, unstack b(3) se(3) star(+ 0.05 * 0.01) replace
	eststo clear

***** Kernel Distribution of Mean Blame by Number Food Waste Mitigating Activiites *****
** We restricted the sample to only means when the respondent report a blame score for the six stakeholders **
	
kdensity XBARI,  nograph generate(x fx)
kdensity XBARI if foodsaversall==0 & bfarm!=. & bgov!=. & bgroc!=. & bfoods!=. & bfman!=.  ///
			& bind!=. , nograph generate(fx0) at(x)
kdensity XBARI if foodsaversall==1 & bfarm!=. &  bgov!=. & bgroc!=. & bfoods!=. & bfman!=.  ///
			&  bind!=. , nograph generate(fx1) at(x)
kdensity XBARI if foodsaversall==2 & bfarm!=. &  bgov!=. & bfoods!=. & bgroc!=. &  bfman!=.  ///
			&  bind!=. , nograph generate(fx2) at(x)
kdensity XBARI if foodsaversall==3 & bfarm!=. &  bgov!=. & bfoods!=. & bgroc!=. & bfman!=.  ///
			&  bind!=. , nograph generate(fx3) at(x)
kdensity XBARI if foodsaversall==4 & bfarm!=. &  bgov!=. & bfoods!=. & bgroc!=. & bfman!=.  ///
			& bind!=. , nograph generate(fx4) at(x)
kdensity XBARI if foodsaversall==5 & bfarm!=. &  bgov!=. & bfoods!=. & bgroc!=. & bfman!=.  ///
			& bind!=. , nograph generate(fx5) at(x)
kdensity XBARI if foodsaversall==6 & bfarm!=. &  bgov!=. & bfoods!=. & bgroc!=. & bfman!=.  ///
			& bind!=. , nograph generate(fx6) at(x)

label var fx0 "0"
label var fx1 "1"
label var fx2 "2"
label var fx3 "3"
label var fx4 "4"
label var fx5 "5"
label var fx6 "6 or more"
line fx0 fx1 fx2 fx3 fx4 fx5 fx6 x, sort ytitle(Density)
drop x fx*



***** Bar Graph *****
/** 
The next line creates frequency distributions just for subjects that have no missing
values for the blame score for the six stakeholders that will be compared on the bar graph
*/

tab1 bgov bfoods bgroc bfman bfarm bind 
tab1 bgov bfoods bgroc bfman bfarm bind if bgov !=. & bfoods !=. & bgroc !=. & ///
	bfman !=. & bfarm !=. & bind !=.  & foodsaversall !=. & region !=. & collegedegree !=. & ///
	sex !=. & income !=. & foodassist !=. & white !=. & age !=. & hhsize !=. & children !=.


* Step 1: Create a set of variables that are numbered 
gen r1=bfarm
gen r2=bfman
gen r3=bgov
gen r4=bgroc
gen r5=bind
gen r6=bfoods

* Reshaping the data from wide to long 

reshape long r, i(uin) j(blame)
list uin r blame in 1/20

/*ssc install catplot*/
* We can label our variables so the labels appear on the graph

/* 
We use the catplot command to create our bar graph.
The "r" variable denotes the stakeholder.  Each stakeholder will be presented on the y axis of the graph.
The "blame" variable indicates the level of blame.  It will be presented on the x axis.
*/

label variable r "Stakeholder"
capture label drop blabel
label define blabel 1 "Not to Blame" 2 "Somewhat to Blame" 3 "Primarily to Blame"
label values r blabel 
capture label drop res
label define res 1 "Farmers" 2 "Food Manufacturers" 3 "Government Policies" 4 "Grocery Stores" 5 "Individuals" 6 "Restaurants & Food Service"
label values blame res

catplot  r, over(blame) stack asyvars  perc(blame)	///
blabel(bar, position(center) format(%3.1f)) ///
legend(on) 

